package com.kmproject.haifu.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.kmproject.haifu.mvp.contract.CustomRentingSeekingListContract;
import com.kmproject.haifu.mvp.model.api.service.UserService;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.RentSeekingDetail;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;

/**
 *
 */
@ActivityScope
public class CustomRentingSeekingListModel extends BaseModel implements CustomRentingSeekingListContract.Model {
    private Gson mGson;
    private Application mApplication;
    private UserService userService;

    @Inject
    public CustomRentingSeekingListModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
        super(repositoryManager);
        this.mGson = gson;
        this.mApplication = application;
        userService = repositoryManager.obtainRetrofitService(UserService.class);
    }

    @Override
    public Observable<ResultBean<List<RentSeekingDetail>>> getRentSeekingList(Map<String, Object> maps) {
        return userService.houseRentSeekingByUser(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean> deleteRentSeeking(String seekingId) {
        Long[] ids = {Long.parseLong(seekingId)};
        Map<String, Object> maps = new HashMap<>();
        maps.put("seekingIds", Arrays.asList(ids));
        return userService.deleteRentSeeking(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean<List<RentSeekingDetail>>> getCollectionSeekingList(Map<String, Object> maps) {
        return userService.userCollectionSeekingQuery(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean> unCollectionSeeking(Map<String, Object> maps) {
        return userService.cancelHouseRentSeekingCollection(creatRequestBody(maps, mGson));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }
}